local youxing = fk.CreateSkill{
  name = "rfenghou_3d18j__youxing",
  tags = { Skill.Lord, Skill.Limited },
}

youxing:addEffect(fk.RoundStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(youxing.name) and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = youxing.name,
      prompt = "#rfenghou_3d18j__youxing-invoke",
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = player:getCardIds("h")
    player:showCards(cards)
    local names = {}
    for _, cid in ipairs(cards) do
      local c = Fk:getCardById(cid)
      names[c.trueName] = true
    end
    local basics = table.filter(Fk:getAllCardNames("b", true), function(tn)
      return not names[tn]
    end)
    local obtains = {}
    local delay_timer = {
      400, 400, 400, 400, 400, 400, 400, 360, 320, 280, 240, 200, 160, 120, 80, 40
    }
    local delay_max = 16
    local delay_index = 1
    while next(basics) and #room.draw_pile > 0 do
      local c1 = Fk:getCardById(room:getNCards(1)[1])
      local found = table.contains(basics, c1.trueName)
      local delay = 40
      if found then
        delay = 400
        delay_index = 1
      else
        delay = delay_timer[delay_index]
        if delay_index < delay_max then
          delay_index = delay_index + 1
        end
      end
      room:turnOverCardsFromDrawPile(player, {c1.id}, youxing.name, true)
      room:delay(delay)
      if found then
        room:obtainCard(player, c1, true, fk.ReasonPrey, player, youxing.name)
        table.insert(obtains, c1)
        table.removeOne(basics, c1.trueName)
      end
    end
    room:cleanProcessingArea(nil, youxing.name)

    room:addPlayerMark(player, "@@rfenghou_3d18j__youxing-round")
  end
}, { check_skill_limit = true })

Fk:loadTranslationTable{
  ["rfenghou_3d18j__youxing"] = "犹兴",
  [":rfenghou_3d18j__youxing"] = "主公技，限定技，轮次开始时，你可展示所有手牌，检索其中缺少的每种基本牌各一张，然后本轮【闪】或【酒】也可发动“浇廷”。",

  ["#rfenghou_3d18j__youxing-invoke"] = "犹兴：你可展示所有手牌，检索其中缺少的每种基本牌各一张，然后本轮【闪】或【酒】也可发动“浇廷”",

  ["@@rfenghou_3d18j__youxing-round"] = "犹兴",
}

return youxing
